package com.szw.dlyk.web;


import com.szw.dlyk.DlykServerApplication;
import com.szw.dlyk.domain.Activity;
import com.szw.dlyk.domain.DicValue;
import com.szw.dlyk.domain.Product;
import com.szw.dlyk.result.DicEnum;
import com.szw.dlyk.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DicController {

    @GetMapping(value = "/api/dicvalue/{typeCode}")
    public Result dicData(@PathVariable(value = "typeCode") String typeCode) {
        if (typeCode.equals(DicEnum.ACTIVITY.getCode())) {
            List<Activity> activityList = (List<Activity>) DlykServerApplication.cacheMap.get(typeCode);
            return Result.ok(activityList);
        } else if (typeCode.equals(DicEnum.PRODUCT.getCode())) {
            List<Product> productList = (List<Product>)DlykServerApplication.cacheMap.get(typeCode);
            return Result.ok(productList);
        } else {
            List<DicValue> dicValueList = (List<DicValue>)DlykServerApplication.cacheMap.get(typeCode);
            return Result.ok(dicValueList);
        }
    }
}
